var tabs = [ "名片夹", "公司通讯录", "浏览足迹" ], TABS_ID = [ "cardcase", "company", "track" ];

Page({
    data: {
        tabs: tabs,
        activeIndex: 0,
        loads: [ 0 ]
    },
    onLoad: function() {
        var t = this.$appData.card;
        this.setCardData(t), this.$addListener("card.change", this.setCardData.bind(this));
    },
    onReady: function() {
        this.getFn("onReady");
    },
    onShow: function() {
        this.getFn("onShow");
    },
    onHide: function() {
        this.getSearch()._onHideInput(), this.getFn("onHide");
    },
    onTabItemTap: function() {
        this.$report("tabbar_contact");
    },
    onPullDownRefresh: function() {
        this.getTab().onPullDownRefresh();
    },
    onReachBottom: function() {
        this.getTab().onReachBottom();
    },
    setCardData: function(t) {
        this.setData({
            card: t
        }), t && t.cardid || this.$route("/pages/tabbar/card/card", "tab");
    },
    navChangeReport: function(t) {
        if (2 !== t) {
            this.$report([ "contact_tap_cardcase", "contact_tap_corp" ][t]);
        }
    },
    SEARCH_RECORD_TAB: [],
    onNavChange: function(t) {
        var e = this, a = t.detail, n = a.index;
        a.reset;
        this.navChangeReport(n);
        var i = this.data.loads, o = {
            activeIndex: n
        };
        i.includes(n) || (i.push(n), o.loads = i), this.lastIndex = this.data.activeIndex, 
        this.setData(o, function() {
            wx.pageScrollTo({
                scrollTop: 0
            }), e.cleanSearch(n);
        });
    },
    cleanSearch: function(t) {
        if (this.lastIndex !== t) {
            if (this.SEARCH_RECORD_TAB.includes(t)) return;
            this.SEARCH_RECORD_TAB.push(t), this.inputShowed ? this.keyword ? (this.getTab().onSearch(this.keyword), 
            this.getTab().tiggerSearch(!0)) : (this.getSearch().hide(), this.getTab(this.lastIndex).tiggerSearch(!1)) : this.getSearch()._onHideInput();
        }
    },
    getSearch: function() {
        return this.selectComponent("#search") || {
            hide: function() {},
            _onHideInput: function() {}
        };
    },
    getTab: function(t) {
        return t = void 0 !== t ? t : this.data.activeIndex, this.selectComponent("#" + TABS_ID[t]) || {};
    },
    getFn: function(t) {
        var e = this.getTab(), a = e[t];
        return a ? a.call(e) : console.log('"' + t + '" Without this function');
    },
    onSearch: function(t) {
        var e = t.detail.value;
        e && (this.keyword = e, this.getTab().onSearch(e));
    },
    tiggerSearch: function(t) {
        var e = t.detail.inputShowed;
        this.inputShowed = e, this.getTab().tiggerSearch(e), e || (this.SEARCH_RECORD_TAB = []);
    },
    onShareAppMessage: function() {
        var t = this.getFn("onShareAppMessage");
        return t || {};
    }
});